package com.imooc.o2o.web.superadmin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.imooc.o2o.entity.Area;
import com.imooc.o2o.service.AreaService;


@Controller
@RequestMapping("/superadmin")
public class AreaController {
	//加入运行日志
	Logger logger = LoggerFactory.getLogger(AreaController.class);
	@Autowired
	private AreaService areaService;
	
	@RequestMapping(value = "/listarea", method = RequestMethod.GET)
	@ResponseBody//json格式
	private Map<String, Object> listArea(){
		logger.info("===start===");
		long startTime = System.currentTimeMillis();//获取当前时间
		Map<String, Object> modelMap = new HashMap<String, Object>();
		List<Area> list = new ArrayList<Area>();
		try {
			list = areaService.getAreaList();//获取区域信息
			//放进modelMap,传给前台
			modelMap.put("rows", list);//因为用的前端是easyUI,rows代表每页的信息
			modelMap.put("total", list.size());//每页的总数
		} catch (Exception e) {
			e.printStackTrace();
			//数据获取失败
			modelMap.put("success", false);
			modelMap.put("errMsg", e.toString());
		}
		logger.error("test error!");//测试错误输出
		long endTime = System.currentTimeMillis();//时间
		logger.debug("costTime:[{}]", endTime - startTime);//运行所用时间
		logger.info("===end===");
		//最后返回modelMap
		return modelMap;
	}
}
